<template>
	<view class="con-box">
		<u-navbar title="" height="120upx">
			<view class="u-nav-slot" slot="left">
				<view @tap="back" class="icon-left">
					<u-icon name="arrow-left" color="#000" size="20"></u-icon>
				</view>
			</view>
			<view class="u-nav-slot logoBox" slot="center">
				<view class="navBox">我的地址</view>
			</view>
			<view class="u-nav-slot" slot="right">
				<view class="icon-right"></view>
			</view>
		</u-navbar>
		<view class="" v-if="siteList.length > 0">
			<view class="item" v-for="(res, index) in siteList" :key="res.id">
				<u-icon name="trash" :size="20" color="#999999" class="guanbi" @tap="trashClick(res.id)"></u-icon>
				<view class="top">
					<view class="name">{{ res.receiver }}</view>
					<view class="phone">{{ res.mobile }}</view>
					<view class="tag">
						<text v-if="res.isDefault == 1" class="red">默认</text>
					</view>
				</view>
				<view class="bottom">
					{{res.address}}{{res.detaileAds}}
					<u-icon name="edit-pen" :size="20" color="#999999" @tap="editClick(res.id)"></u-icon>
				</view>
			</view>
		</view>
		<view v-else class="noListBox">
			<view class="noData">
				<image class="noDataImg" src="../../static/home/noData.png" mode=""></image>
				<view class="text">暂无收货地址</view>
			</view>
		</view>
		<view class="submit-bottom" @tap="toAddSite">
			<view class="submit-btn">
				<u-icon name="plus" color="#ffffff" class="icon" :size="20"></u-icon>新建收货地址
			</view>
		</view>
	</view>
</template>

<script>
	import {
		appaddress_select,
		appaddress_remove
	} from "@/api/user.js";
	export default {
		data() {
			return {
				listQuery: {
					total: 0,
					page: 1,
					pageSize: 10,
				},
				siteList: [{
					receiver:'张三',
					mobile:18634445878,
					isDefault:1,
					address:'北京市',
					detaileAds:'少时诵诗书所所所所'
				}]
			};
		},
		onLoad() {

		},
		onShow() {
			this.getData();
		},
		methods: {
			// 删除
			trashClick(id) {
				appaddress_remove(id).then(res => {
					if (res.data.success) {
						this.$u.toast('删除成功')
						this.getData();
					} else {
						this.$u.toast('删除失败,请稍后重试')
					}
				})
			},
			back() {
				let canNavBack = getCurrentPages();
				if (canNavBack && canNavBack.length > 1) {
					uni.navigateBack({
						delta: 1
					});
				} else {
					history.back();
				}
			},
			// 编辑
			editClick(id) {
				uni.navigateTo({
					url: './addAddress?id=' + id
				})
			},
			// 获取
			getData() {
				appaddress_select(this.listQuery).then(res => {
					this.siteList = res.data.rows
				})
			},
			toAddSite() {
				uni.navigateTo({
					url: './addAddress'
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	page{
		background-color: #fff;
	}
	.con-box {
		width: 100%;
		padding: 0 32upx 0;
		/* #ifdef APP-PLUS */
		padding-top: calc(120upx + var(--status-bar-height));
		/* #endif */
		/* #ifdef H5 */
		padding-top: 140upx;
		/* #endif */
		min-height: 100vh;
	}
	
	.logoBox {
		width: 100%;
		height: 100%;
	
		.navBox {
			height: 120upx;
			background-color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 32upx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #333333;
			box-shadow: 0px 0px 1px 0px rgba(51, 51, 51, 0.5000);
		}
	}

	.item {
		padding: 40upx 20upx;
		color: #EEEEEE;
		position: relative;
		border-bottom: 1upx solid rgba(51, 51, 51, 0.5000);

		.guanbi {
			position: absolute;
			top: 20upx;
			right: 20upx;
		}

		.top {
			display: flex;
			font-weight: bold;
			font-size: 34upx;
			color:#333;

			.phone {
				margin-left: 60upx;
			}

			.tag {
				display: flex;
				font-weight: normal;
				align-items: center;

				text {
					display: block;
					width: 60upx;
					height: 34upx;
					line-height: 34upx;
					color: #ffffff;
					font-size: 20upx;
					border-radius: 6upx;
					text-align: center;
					margin-left: 30upx;
					background-color: rgb(49, 145, 253);
				}

				.red {
					background-color: #CEA539;
				}
			}
		}

		.bottom {
			display: flex;
			margin-top: 20upx;
			font-size: 28upx;
			justify-content: space-between;
			color: #333;
		}
	}
	
	.noListBox {
		text-align: center;
		.noData {
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			margin-top: 200upx;
			.noDataImg {
				width: 316upx;
				height: 126upx;
			}
			
			.text{
				font-size: 26upx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #B0B5BC;
				line-height: 92upx;
			}
		}
	}

	// .addSite {
	// 	display: flex;
	// 	justify-content: space-around;
	// 	line-height: 80upx;
	// 	position: absolute;
	// 	bottom: 30upx;
	// 	left: 80upx;
	// 	background: linear-gradient(89.99deg, #FFAD02 7%, #FE9F38 89.24%);
	// 	border-radius: 60upx;
	// 	font-size: 30upx;

	// 	.add {
	// 		display: flex;
	// 		align-items: center;
	// 		color: #ffffff;

	// 		.icon {
	// 			margin-right: 10upx;
	// 		}
	// 	}
	// }
	.submit-bottom {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		padding: 16upx 50upx 30upx;
		position: fixed;
		bottom: 20upx;
		left: 0;
	
		.submit-btn {
			width: 100%;
			height: 96upx;
			background: #CEA539;
			border-radius: 10upx;
			font-size: 32upx;
			font-weight: bold;
			color: #FFFFFF;
			display: flex;
			align-items: center;
			justify-content: center;
			
			.icon {
				margin-right: 10upx;
			}
		}
	}
</style>
